﻿using System;
using System.Linq;
using System.Web.UI.WebControls;

namespace TeamFranceTriple
{
    public partial class UserPanel : BaseUserControl
    {
        private HyperLink HeadLoginStatusLink, ChangePasswordLink;
        private LoginStatus HeadLoginStatus;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            Gravatar1.Email = ThisMaster.Requester.Profile.UserGravatarEmail;
            UserInfoPanel.Visible = ThisMaster.Requester.IsAuthenticated;
            AwaitingUserHyperLink.Enabled = ThisMaster.Requester.Roles.Contains("RoleHR");

            UserProfile1.NavigateUrl =String.Format("~/{0}/userprofile",ThisMaster.Requester.Culture);

            HeadLoginStatusLink = (HyperLink)(HeadLoginView.FindControl("HeadLoginStatusLink"));
            if (HeadLoginStatusLink != null)
                HeadLoginStatusLink.NavigateUrl = String.Format("~/{0}/connexion/?returnurl={1}", ThisMaster.Requester.Culture, this.Page.Request.RawUrl);

            ChangePasswordLink = (HyperLink)(HeadLoginView.FindControl("ChangePasswordLink"));
            if (ChangePasswordLink != null)
                ChangePasswordLink.NavigateUrl =  String.Format("~/{0}/userprofile",ThisMaster.Requester.Culture);

            HeadLoginStatus = (LoginStatus)(HeadLoginView.FindControl("HeadLoginStatus"));
            if (HeadLoginStatus != null)
                HeadLoginStatus.LogoutPageUrl =  String.Format("~/{0}/logout",ThisMaster.Requester.Culture);

            HyperLink1.NavigateUrl = String.Format("~/{0}/userprofile", ThisMaster.Requester.Culture);
            AwaitingUserHyperLink.NavigateUrl =  String.Format("~/{0}/awaitingusers",ThisMaster.Requester.Culture);

            if (ThisMaster.Requester.Membership != null)
            {
                Label3.Text = DateTime.Parse(ThisMaster.Requester.Membership.CreationDate.ToUniversalTime().ToUserTimeZone(ThisMaster.Requester.Profile.TimeZone).ToString()).ToString();
                Label5.Text = DateTime.Parse(ThisMaster.Requester.Membership.LastActivityDate.ToUniversalTime().ToUserTimeZone(ThisMaster.Requester.Profile.TimeZone).ToString()).ToString();
            }
        }
    }
}